﻿﻿<!DOCTYPE html
  PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">

<head>
  <meta http-equiv="X-UA-Compatible" content="IE=EDGE;IE=11;IE=8,chrome=1" />
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  <title>配套单撤销管理</title>
  <link href="/InSiteWebApplication/Content/Easyui/themes/metro/easyui.css" rel="stylesheet" />
  <link href="/InSiteWebApplication/Content/Easyui/custom-easyui.css" rel="stylesheet" />
  <link href="/InSiteWebApplication/Content/Easyui/themes/icon.css" rel="stylesheet" />
  <style>
    .inline-block {
      display: inline-block;
    }

    .divLabel {
      margin-bottom: 5px;
    }

    /* 重写下拉框样式 */
    .select {
      width: 200px;
    }

    .combobox-item {
      height: 32px;
    }

    /* 重写日期框样式 
    .datebox {
      height: 24px !important;
      line-height: 24px !important;
    }*/

    /* 重写文本框样式 */
    #queryZone .textbox-text,
    #dialogQueryZone .textbox-text,
    #processZone .textbox-text {
      line-height: 22px !important;
      height: 22px !important;
    }
  </style>
</head>

<body>
  <div class="panelSection" id="queryZone">
    <div class="easyui-panel " title="查询区域" style="padding:3px 3px 5px;"
      data-options="closable:false,collapsible:true,minimizable:false,maximizable:false">
      <div>
        <div class="inline-block">
          <div class="divLabel">主制分厂:</div>
          <select id='ddlFactory' data-options='editable:true' class='easyui-combobox select'
            style="width:160px;"></select>
        </div>

        <div class="inline-block">
          <div class="divLabel">订单号:</div>
          <input id="txtMfgordername" class="easyui-textbox" style="width:200px;" />
        </div>

        <div class="inline-block">
          <div class="divLabel">零件号:</div>
          <input id="txtProductname" class="easyui-textbox" style="width:200px;" />
        </div>

        <div class="inline-block">
          <div class="divLabel">批次号:</div>
          <input id="txtContainername" class="easyui-textbox" style="width:200px;" />
        </div>

        <div class="inline-block">
          <div class="divLabel">状态:</div>
          <select id='ddlStatus' data-options='editable:false' class='easyui-combobox select' style="width:120px;">
            <option value="">请选择</option>
            <option value="0">正常</option>
            <option value="1">已撤销</option>
          </select>
        </div>
        <button id="btnSearch" class="easyui-linkbutton" data-options="">查 询</button>
        <button id="btnReset" class="easyui-linkbutton" data-options="">重 置</button>
      </div>
    </div>
  </div>

  <div class="panelSection" id="dataGridZone">
    <div class="easyui-panel " title="查询结果" style="padding: 3px;"
      data-options="closable:false,collapsible:true,minimizable:false,maximizable:false">
      <div style="background: #fff; margin: 3px 0px 3px 3px">
        <table id="tbGrid" class="easyui-datagrid" style="height: 350px;" data-options="rownumbers:true">
        </table>
        <div id="pp" style="float: right" class="easyui-pagination" data-options="
                      layout:['list','first','prev','next','last','manual','info'],
                        total: 0,
                        showPageList: true,
                        showPageInfo: false,
                        showRefresh: false,
                        pageList:[10,20,50,100,200],
                        afterPageText:'共&nbsp{pages}&nbsp页'">
        </div>
      </div>
    </div>
  </div>

  <div style="margin:5px;">
    <button id="btnConfirm" class="easyui-linkbutton" data-options="">撤销</button>
  </div>
</body>

</html>
<script src="/InSiteWebApplication/Scripts/json2.js" type="text/javascript"></script>
<script src="/InSiteWebApplication/Content/Easyui/jquery.min.js" type="text/javascript"></script>
<script src="/InSiteWebApplication/Content/Easyui/jquery.easyui.min.js" type="text/javascript"></script>
<script src="/InSiteWebApplication/Content/Easyui/easyui-lang-zh_CN.js" type="text/javascript"></script>
<script src="/InSiteWebApplication/Scripts/array.pollyfill.js" type="text/javascript"></script>
<script src="/InSiteWebApplication/Scripts/CustomPageJs/CustomCommon.js" type="text/javascript"></script>
<script src="/InSiteWebApplication/Scripts/dayjs.min.js" type="text/javascript"></script>
<script type="text/javascript">
  /**
   * 创建人：zhunan
   * 日期：2025.10.15
   * 描述：配套单撤销管理
  */
  var page = {
    pagetotal: 0,
    pageNumber: 1,
    pageSize: 10,
    mainUrl: getRootPath() + "/Ashx/BomRquestCancelPageHandler.ashx", //本页面后台路径
    //初始化页面
    init: function () {
      page.bind();
      page.initData(); //初始化页面数据
    },
    // 页面事件绑定
    bind: function () {
      // 重点批次进度表格
      $("#tbGrid").datagrid({
        columns: [[
          { field: 'ck', title: '选择', checkbox: true },
          { field: 'id', title: 'id', hidden: true },
          { field: 'methodname', title: '类型', width: 100 },
          { field: 'fullname', title: '创建人', width: 80 },
          {
            field: 'createdate', title: '创建时间', width: 100,
            formatter: function (value) {
              if (value) {
                return value.split('T')[0];
              } else {
                return "";
              }
            }
          },
          { field: 'cancleemp', title: '撤销人', width: 80 },
          {
            field: 'lastchangedate', title: '撤销时间', width: 100,
            formatter: function (value) {
              if (value) {
                return value.split('T')[0];
              } else {
                return "";
              }
            }
          },
          {
            field: 'isuse', title: '状态', width: 80,
            formatter: function (value) {
              return value === "0" ? "正常" : "已撤销";
            }
          },
          { field: 'mfgordername', title: '订单号', width: 200 },
          { field: 'containername', title: '批次号', width: 200 },
          { field: 'workflowstepname', title: '工序', width: 100 },
          { field: 'productdescription', title: '零件名称', width: 160 },
          { field: 'qty', title: '在制数', width: 80 },
          { field: 'workflowinfo', title: '工艺规程及版本', width: 160 },
          { field: 'containertype', title: '批次类型', width: 100 },
          {
            field: 'plannedstartdate', title: '计划开始时间', width: 100,
            formatter: function (value) {
              if (value) {
                return value.split('T')[0];
              } else {
                return "";
              }
            }
          },
          {
            field: 'plannedcompletiondate', title: '计划结束时间', width: 100,
            formatter: function (value) {
              if (value) {
                return value.split('T')[0];
              } else {
                return "";
              }
            }
          }
        ]],
        onLoadSuccess: function (data) {
          $('#pp').pagination('refresh', {	// 改变选项，并刷新分页栏信息
            total: page.pagetotal,
            pageSize: page.pageSize,
            pageNumber: page.pageNumber
          });
          customizedEasyuiPagination('pp'); //定制化分页
        },
        onCheck: function (rowIndex, rowData) { }
      });

      //分页事件
      $('#pp').pagination({
        onSelectPage: function (pageNumber, pageSize) {
          customizedEasyuiPagination('pp'); //定制化分页
          page.pageSize = pageSize;
          page.pageNumber = pageNumber;
          page.search();
        }
      });

      // 查询
      $("#btnSearch").on("click", function () {
        page.pageNumber = 1;
        page.search();
      });

      // 重置
      $("#btnReset").on('click', function () {
        page.resetData();
      });

      // 撤销
      $("#btnConfirm").on('click', function () {
        page.saveCancleData();
      });
    },
    // 初始化页面
    initData: function () {
      page.getFactory();
    },
    // 获取分厂列表
    getFactory: function () {
      $.ajax({
        type: "post",
        url: getRootPath() + "/Ashx/ApsHandler/EmployeeMaintPage.ashx?actions=getFactory",
        data: { action: "GetFactory" },
        cashe: false,
        dataType: 'json',
        success: function (res) {
          if (res.Result) {
            // 绑定弹出框分厂下拉框
            $("#ddlFactory").combobox({
              valueField: 'factoryid',
              textField: 'factoryname',
              panelHeight: 200,
              data: res.DBTable
            });

            $.ajax({
              type: "post",
              url: page.mainUrl + "?actions=getUserInfo",
              data: { action: "getUserInfo" },
              cashe: false,
              dataType: 'json',
              success: function (res) {
                if (res.Result) {
                  $("#ddlFactory").combobox('select', res.ReturnData.FactoryID);
                  $('#ddlFactory').combobox('disable');
                } else {
                  displayMessage(res.Message, false);
                }
              }
            });
          }
        }
      });
    },
    // 查询
    search: function () {
      var formData = {
        action: "getData",
        pageSize: page.pageSize,
        pageNumber: page.pageNumber,
        factoryid: $('#ddlFactory').combobox('getValue'),//主制分厂
        mfgordername: $("#txtMfgordername").textbox('getValue'),//订单号
        productname: $("#txtProductname").textbox('getValue'),//零件号
        containername: $('#txtContainername').textbox('getValue'),//批次号
        isuse: $("#ddlStatus").combobox('getValue')//状态
      };

      $.ajax({
        type: "Post",
        url: page.mainUrl + "?actions=getData",
        data: formData,
        cashe: false,
        async: true,
        beforeSend: function () {
          $('#tbGrid').datagrid('loading');
          $(this).attr("disabled", "disabled"); //禁用按钮
        },
        success: function (data) {
          $('#tbGrid').datagrid('loaded');
          $(this).removeAttr("disabled"); //恢复按钮
          var result = JSON.parse(data);
          if (result.Result) {
            //给分页对象赋值
            page.pagetotal = result.RowCount;
            $('#tbGrid').datagrid('loadData', { total: result.RowCount, rows: result.DBTable });
          } else {
            displayMessage(result.Message, false);
          }
        },
        error: function (XMLHttpRequest, textStatus, errorThrown) {
          $('#tbGrid').datagrid('loaded');
          $(this).removeAttr("disabled"); //恢复按钮
          alert(XMLHttpRequest.responseText);
        }
      });
    },
    // 重置
    resetData: function () {
      $("#txtMfgordername").textbox('clear');
      $("#txtProductname").textbox('clear');
      $("#txtContainername").textbox('clear');
      $("#ddlStatus").combobox('select', '');

      $("#tbGrid").datagrid('loadData', { total: 0, rows: [] });
      page.pageNumber = 1;
      page.pageSize = 10;

      $('#pp').pagination('refresh', { // 改变选项并刷新分页栏信息
        total: 0,
        pageNumber: 1,
        pageSize: 10
      });
    },
    // 撤销
    saveCancleData: function () {
      var selectData = $("#tbGrid").datagrid('getChecked');
      if (selectData.length === 0) {
        displayMessage("请勾选需要撤销的记录！", false);
        return;
      }

      if (selectData.some(function (item) { return item.isuse === "1" })) {
        displayMessage("所选的数据中存在已经撤销的数据", false);
        return;
      }

      $.messager.confirm('确认', '你确认要撤销吗?', function (r) {
        if (r) {
          $.ajax({
            type: "post",
            url: page.mainUrl + "?actions=saveCancleData",
            data: {
              action: "saveCancleData",
              postData: JSON.stringify(selectData)
            },
            cashe: false,
            dataType: 'json',
            success: function (res) {
              if (res.Result) {
                $.messager.alert('消息提示', '撤销成功', 'info');
                page.resetData();
                $('#tbGrid').datagrid('loadData', []);
              } else {
                displayMessage(res.Message, false);
              }
            }
          });
        }
      });
    }
  };

  $(function () {
    page.init();
  });
</script>